package engine.gui;

import engine.Engine;
import engine.game.Game;
import engine.game.Manager;
import engine.graphics.Color4f;
import engine.graphics.FontManager;
import engine.graphics.TextureManager;
import engine.graphics.Vertex2f;
import engine.gui.events.EventMethod;
import engine.objects.TexturedObject;

public abstract class GameMenuScreen extends MenuScreen {

	private static final long serialVersionUID = 1L;
	
	private static final int WIDTH = 400, HEIGHT = 400 ; 
	
	public GameMenuScreen(Manager m, Game g) {
		super(m, g, (Engine.WIDTH - WIDTH) / 2, (Engine.HEIGHT - HEIGHT) / 2, WIDTH, HEIGHT);
	}
	
	public void addNewButton(String caption, EventMethod event){
		this.addNewButton(this.getMainScreen(), caption, event);
	}
	
	public void addNewButton(Panel screen, String caption, EventMethod event){
		int i =  screen.getAllChildren().size();
		GameButton tmp = new GameButton(this.getManager(), (int) this.getMinX()+50, 
					(int)this.getMaxY() - (i*45), 300, 30); 
		tmp.changeCaption(caption);
		tmp.getLabel().setFontName(FontManager.S_FONT_13);
		int px = (tmp.getObjectWidth() - (caption.length()*FontManager.getFontByName(tmp.getLabel().getFontName()).getFont().getSize() / 3 * 2)) / 2 ; 
		tmp.labelPadding(px, -9);
		tmp.onClick(event);
		screen.addNewChild(tmp.toString(), tmp);	
	}
	

	public void render(){
		if(this.getBackgroundPanel().isTextured())
			TextureManager.bindTexture("gui"); 
		super.render(); 
	}
	
	public static void textureGameMenuScreen(GameMenuScreen screen) {
		screen.getBackgroundPanel().changeNormalColor(new Color4f(1,1,1,1)); 
		TexturedObject.addNewAnimationToObject(screen.getBackgroundPanel(), "gameMenuScreen", "gui",
				new Vertex2f[]{new Vertex2f(400,400)}, 
				new Vertex2f[]{new Vertex2f(0, 30)}, 0); 
	}
	
}
